<template>
  <div class="document-menu">
    <image src="@/assets/document/icon-menu.png" class="document-menu__icon" />
    <div
      v-for="(item, index) in options"
      :key="index"
      :class="[modelValue === item.id && 'is-active']"
      class="document-menu__item"
      @tap="onSelect(item.id)"
    >
      <div className="document-menu__item-inner">
        <span>{{ item.name }}</span>
      </div>

      <template v-if="modelValue === item.id">
        <div v-if="index !== 0" className="document-menu__item-left" />
        <div className="document-menu__item-right" />
      </template>
    </div>
  </div>
</template>

<script lang="ts" setup>
defineOptions({
  name: "document-menu",
});

const props = withDefaults(
  defineProps<{
    options?: any[];
    modelValue?: number | null;
  }>(),
  {
    options: () => [],
  }
);

const emits = defineEmits(["update:modelValue"]);

const onSelect = (value: number) => {
  if (props.modelValue !== value) {
    emits("update:modelValue", value);
  }
};
</script>

<style lang="less">
.document-menu {
  width: 100%;
  display: flex;
  align-items: flex-end;
  --radial-size: 30px;
  --category-item-bg-color: #fbfffe;
  transition: all 0.5s;
  background-color: #eaf8f6;
  border-radius: 30px 30px 0 0;
  position: relative;

  &__icon {
    position: absolute;
    width: 148px;
    height: 92px;
    top: 4px;
    right: 30px;
  }

  &__item {
    position: relative;
    border-radius: 30px 30px 0 0;
    color: #8b8b8b;
    font-weight: bold;
    font-size: 30px;
    letter-spacing: 2px;
    line-height: 44px;
    &-inner {
      width: 100%;
      height: 100%;
      padding: 20px 40px;
      box-sizing: border-box;
    }
    &.is-active {
      font-weight: bold;
      font-size: 34px;
      color: #000000;
      line-height: 50px;
      background-color: var(--category-item-bg-color);
    }

    &-left,
    &-right {
      position: absolute;
      width: var(--radial-size);
      height: var(--radial-size);
      bottom: 0;
    }
    &-left {
      left: calc(var(--radial-size) * -1);
      background: radial-gradient(
        circle at 0 0,
        transparent var(--radial-size),
        var(--category-item-bg-color) calc(var(--radial-size) + 1px)
      );
    }
    &-right {
      right: calc(var(--radial-size) * -1);
      background: radial-gradient(
        circle at 100% 0,
        transparent var(--radial-size),
        var(--category-item-bg-color) calc(var(--radial-size) + 1px)
      );
    }
  }
}
</style>
